package middleware

import (
	"github.com/gogf/gf/net/ghttp"
	"net"
	"strings"
)

func MiddlewareHttpLog(r *ghttp.Request) {
	r.Middleware.Next()
	// 中间件处理逻辑
	xForwardedFor := r.Request.Header.Get("X-Forwarded-For")
	ip := strings.TrimSpace(strings.Split(xForwardedFor, ",")[0])
	if ip == "" {
		ip = strings.TrimSpace(r.Request.Header.Get("X-Real-Ip"))
		if ip == "" {
			ip, _, _ = net.SplitHostPort(strings.TrimSpace(r.Request.RemoteAddr))
		}
	}
	//params,_:=json.Marshal(r.GetMap())
	//设置当前访问的路由的权限标识
	// apiCode := utils.RouteToAuthCode(r.Router.Uri, r.Router.Method)
	// 判断路由是否需要登录
	//apiRoute := authValid.AuthCodeGetRoute(apiCode)
	/*fmt.Println("==========================请求日志========================")
	fmt.Println("请求IP：",ip)
	fmt.Println("请求方式：",r.Method)
	fmt.Println("请求URL：",r.URL)
	fmt.Println("匹配路由：",r.Router.Uri)
	//fmt.Println("请求功能：",apiRoute.Title)
	fmt.Println("请求参数：",string(params))
	fmt.Println("请求状态：",r.Response.Status)
	fmt.Println("请求数据：",string(r.Response.Buffer()))
	fmt.Println("=========================================================")*/
}
